import { ajaxAsync } from 'vue-xiaobu-utils'
import AjaxForBusOpen from '@/utils/AjaxForBusOpen'
import OrderListModels from '../models/OrderListModels'

/**
 * 获取包车全局配置信息
 */
async function getGlobals() {
  let postData = {}
  let res
  res = await AjaxForBusOpen('/chartered-bus-api/chartered/globals', postData)
  return res
}

/**
 * 获取包车订单列表
 * @param {*} pageIndex
 * @param {*} pageCapacity
 */
async function getBCOrderList(pageIndex, pageCapacity) {
  let postData = {
    SESSION_ID: localStorage.getItem('XIAOBUSESSION'),
    GOODS_TYPE: 7,
    PAGE_CAPACITY: pageCapacity,
    PAGE_INDEX: pageIndex
  }
  let res
  res = await ajaxAsync('/order/bos/list', postData)
  let orderList = []
  if (res.LIST) {
    res.LIST.forEach(item => {
      orderList.push(
        new OrderListModels(
          item.ORDER_ID,
          item.OUT_ORDER_NO,
          item.ORDER_STATE,
          item.PAY_FEE,
          item.OP,
          item.STORE_ORDER[0].STORE_NAME,
          item.STORE_ORDER[0].SKU_LIST[0].SKU_NAME,
          item.STORE_ORDER[0].SKU_LIST[0].SKU_NUM,
          item.STORE_ORDER[0].SKU_LIST[0].SKU_PIC,
          item.PAYMENT
        )
      )
    })
  }

  let body = {
    count: res.COUNT,
    list: orderList
  }
  return body
}

export { getGlobals, getBCOrderList }
